package com.tma.internship.activities;

import com.tma.internship.ClassesInfo.BookmarkAdapter;
import com.tma.internship.ClassesInfo.CommentInfo;
import com.tma.internship.ClassesInfo.ControlBookMark;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ControlBookmarkDialog extends Dialog implements android.view.View.OnClickListener{
	private Context context;
	public ControlBookmarkDialog(Context context,CommentInfo cmtInfo,BookmarkAdapter adapter) {
		super(context);
		// TODO Auto-generated constructor stub
		this.cmtInfo = cmtInfo;
		this.adapter = adapter;
		this.context = context;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == viewBtn) {
			Intent intent = new Intent(getContext(), ViewBookActivity.class);
			intent.putExtra("file", cmtInfo.getfInfo());
			intent.putExtra("page", cmtInfo.getPage());
			getContext().startActivity(intent);
			dismiss();
			((Activity) context).finish();
		} else if (v == deleteBtn){
			ControlBookMark ctr = new ControlBookMark(getContext());
			ctr.deleteCmtOnPage(cmtInfo.getBookName(), cmtInfo.getPage());
			adapter.remove(cmtInfo);
			adapter.notifyDataSetChanged();
			dismiss();
		} else {
			dismiss();
		}
	}
	private BookmarkAdapter adapter;
	private CommentInfo cmtInfo;
	private Button viewBtn;
	private Button cancelBtn;
	private Button deleteBtn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bookmark_control_item);
		viewBtn = (Button) findViewById(R.id.view_bookmark);
		deleteBtn = (Button) findViewById(R.id.delete_bookmark);
		cancelBtn = (Button) findViewById(R.id.cancel_bookmark);
		viewBtn.setOnClickListener(this);
		deleteBtn.setOnClickListener(this);
		cancelBtn.setOnClickListener(this);
		setCancelable(true);
	}
	
}
